const { DataTypes, Model } = require('sequelize');
const { sequelize } = require('../config/db');
const DataSource = require('./DataSource.js');
const ManagedModel = require('./ManagedModel.js');


let ModelTask = sequelize.define('ModelTask',{
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  description: {
    type: DataTypes.TEXT,
  },
  dataSourceId: {
    type: DataTypes.INTEGER,
    references: {
      model: DataSource,
      key: 'id',
    }
  },
  modelId: {
    type: DataTypes.INTEGER,
    references: {
      model: ManagedModel,
      key: 'id',
    }
  }
}, {
  tableName: 'model_tasks',
  timestamps: true,
});

ModelTask.belongsTo(DataSource, { foreignKey: 'dataSourceId' });
ModelTask.belongsTo(ManagedModel, { foreignKey: 'modelId' });

module.exports = ModelTask;